﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace DHQGHN.PM0.Models.Admin
{
    public class EthnicModel
    {
        public string Ethnic_ID { get; set; }

        [Remote("CheckExistEthnicName", "Ethnic", ErrorMessage = "EthnicNameExist", HttpMethod = "POST", AdditionalFields = "Ethnic_ID")]
        [Required(AllowEmptyStrings = false, ErrorMessage = "Bạn chưa nhập tên dân tộc")]
        [StringLength(255, ErrorMessage = "Độ dài vượt quá 255 ký tự")]
        [Display(Name = "Tên dân tộc")]
        public string Name { get; set; }

        [Remote("CheckExistEthnicCode", "Ethnic", ErrorMessage = "EthnicCodeExist", HttpMethod = "POST", AdditionalFields = "Ethnic_ID")]
        [Required(AllowEmptyStrings = false, ErrorMessage = "Bạn chưa nhập mã dân tộc")]
        [Display(Name = "Mã dân tộc")]
        [StringLength(12, ErrorMessage = "Độ dài vượt quá 12 ký tự")]
        [RegularExpression(@"^[a-zA-Z0-9]+[a-zA-Z0-9_]*[a-zA-Z0-9]*$", ErrorMessage = "Mã không đúng định dạng")]
        public string Code { get; set; }

        [Display(Name = "Mô tả")]
        [StringLength(255, ErrorMessage = "Độ dài vượt quá 255 ký tự")]
        public string Descriptions { get; set; }

        public int Deleted { get; set; }
        public int RecordCount { get; set; }
        public const string FIELD_RECORD_COUNT = "RecordCount";

        #region Field list from database
        public const string FIELD_ID = "ETHNIC_ID";
        public const string FIELD_NAME = "NAME";
        public const string FIELD_CODE = "CODE";
        public const string FIELD_DESCRIPTIONS = "DESCRIPTIONS";
        #endregion

        public EthnicModel() { }

        public EthnicModel(DAL.Models.Admin.EthnicModel model)
        {
            // TODO: Complete member initialization
            Ethnic_ID = model.Ethnic_ID;
            Code = model.Code;
            Name = model.Name;
            Deleted = model.Deleted;
            Descriptions = model.Descriptions;
            RecordCount = model.RecordCount;
        }

      
        internal DAL.Models.Admin.EthnicModel toDALModel()
        {
            DAL.Models.Admin.EthnicModel model = new DAL.Models.Admin.EthnicModel
            {
                Ethnic_ID = Ethnic_ID,
                Code = Code,
                Name = Name,
                Deleted = Deleted,
                Descriptions = Descriptions,
                RecordCount = RecordCount
            };
            return model;
        }
    }
}